﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class represents a nonlinear system of equation.
    /// </summary>
    [Serializable]
    public class NonLinearEquationSystem
    {
        /// <summary>
        /// The functions, which define the nonlinear real system of equation.
        /// </summary>
        private HardMultivariateRealFunction[] equationSystem;

        /// <summary>
        /// Initializes a new instance of the <see cref="NonLinearEquationSystem"/> class.
        /// </summary>
        /// <param name="equationSystem">The functions, which define the nonlinear system of equation.</param>
        public NonLinearEquationSystem(HardMultivariateRealFunction[] equationSystem)
        {
            if (equationSystem == (HardMultivariateRealFunction[]) null)
            {
                throw new ArgumentNullException("equationSystem");
            }

            this.equationSystem = equationSystem;
        }

        /// <summary>
        /// Gets or sets the functions, which define the nonlinear system of equation.
        /// </summary>
        /// <value>The functions, which define the nonlinear system of equation.</value>
        public HardMultivariateRealFunction[] EquationSystem
        {
            get { return equationSystem; }
            set { equationSystem = value; }
        }

        /// <summary>
        /// Solves all equations in nonlinear system of equation at the specified vector.
        /// </summary>
        /// <param name="vector">The specified vector.</param>
        /// <returns>The results of the equations in the system.</returns>
        public GeneralVector SolveAt(GeneralVector vector)
        {
            GeneralVector result = new GeneralVector(this.equationSystem.Length);

            for (int i = 0; i < this.equationSystem.Length; i++)
            {
                result[i] = this.equationSystem[i].SolveAt(vector);
            }

            return result;
        }
    }
}